package paginate

import "math"

//分页结构体
type Paginate struct {
	Page       int64 `json:"page"`        //页码
	PageSize   int64 `json:"page_size"`   //每页条数
	Limit      int   `json:"limit"`       //获取条数
	Start      int   `json:"start"`       // 从第几条开始获取
	TotalCount int64 `json:"total_count"` //总记录页数
	TotalPage  int64 `json:"total_page"`  //总页数
}

//返回分页的数据
type PaginateData struct {
	Data     interface{} `json:"data"`     //分页时返回的数据
	Paginate *Paginate    `json:"paginate"` //分页信息
}

//计算分页数据totalCount总记录条数
func (this *Paginate) CalcPaginate(totalCount int64) {
	if this.Page <= 0 {
		this.Page = 1
	}
	if this.PageSize <= 0 {
		this.PageSize = 12
	}
	this.Limit = int(this.PageSize)
	this.Start = int((this.Page - 1) * this.PageSize)
	this.TotalCount = totalCount
	this.TotalPage = int64(math.Ceil(float64(totalCount) / float64(this.PageSize)))
}
